using System.ComponentModel;
using System.Web.Services;
using System.Web.Services.Protocols;

using TfsSpam.Utilities;

namespace TfsSpam.Service
{
    /// <summary>
    /// The CheckinEvent class implements a web service that listens for TFS events
    /// (specifically CheckinEvent occurrences) and hands them off to be processed
    /// by the <see cref="CheckinEventProcessor"/> class.
    /// </summary>
    [WebService( Namespace = "http://www.codeplex.com/tfsspam/" )]
    [WebServiceBinding( ConformsTo = WsiProfiles.BasicProfile1_1 )]
    [ToolboxItem( false )]
    public class CheckinEvent : System.Web.Services.WebService
    {
        /// <summary>
        /// Implements the Notify methods which is called by TFS
        /// to provide information about an event the service has
        /// been registered for.
        /// </summary>
        /// <param name="eventXml">The information provided about the event.</param>
        [SoapDocumentMethod( 
            Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify",
            RequestNamespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03"
        )]
        [WebMethod]
        public void Notify( string eventXml )
        {
            TfsLogger logger = new TfsLogger();

            logger.Verbose( "Received a notification: {0}", eventXml );
            EventDispatcher.Dispatch( eventXml, Context.Request.Url.AbsolutePath );
            logger.Verbose( "Successfully dispatched an event notification" );
        }
    }
}
